<script setup lang="ts">
import { remove } from 'lodash'
import { ref } from 'vue'

const props = withDefaults(
  defineProps<{
    data: string[]
    showCheckBox?: boolean
  }>(),
  {
    data: () => [] as string[],
    showCheckBox: false
  }
)
const emit = defineEmits(['update'])
const checked: any = ref([])

function setFormChecked (i: string) {
  if (checked.value.includes(i)) {
    remove(checked.value, (v) => v === i)
  } else {
    checked.value.push(i)
  }
  emit('update', checked.value)
}
</script>

<template>
  <div class='checkbox-item' v-for="(item, index) in props.data" :key="index" @click="setFormChecked(item)">
    <div>
      {{ index + 1 }}、 {{ item }}
    </div>
    <div v-if="props.showCheckBox">
      <img v-if="checked.includes(item)" src="@/assets/agent/chat/checkboxed.svg" alt="">
      <img v-else src="@/assets/agent/chat/checkbox.svg" alt="">
    </div>
  </div>
</template>

<style scoped lang="scss">
.checkbox-item {
  width: 87%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  border-radius: 6px 6px 6px 6px;
  border: 1px solid #DFE0E3;
  padding: 6px 12px;
  margin-bottom: 10px;
  div {
    font-weight: 400;
    font-size: 14px;
    color: #333333;
    line-height: 20px;
  }
}
</style>
